int a[300];
void createTree(int begin, int end, Node* p){
	if(begin>end)
		return;
	//find middle element
	int middle=(begin+end)/2;
	p=new Node(a[middle],null,null);
	createTree(begin,middle-1,p->left);
	createTree(middle+1,end,p->right);
	return;
}
	


list<TreeNode*> findLayers(TreeNode* root){
	list<list<TreeNode*> > layers;
	list<TreeNode*> visiting;
	visiting.push_back(root);	
	while(true){
		int sz=visiting.size();
		if(sz==0)
			break;
		list<TreeNode*> ll;
		for(int i=0;i<sz;i++){
			TreeNode* n=visiting.pop_front();
			ll->push_back(n);
			if(n.right!=NULL)
				visiting.push_back(n.right);
			if(n.left!=NULL)
				visiting.push_back(n.left);
		} 
		layers.push_back(ll);
	}
	
}


if(n==root)
	while(n->next!=NULL)
		n=n->next;
	return n;
while(n->parent->right!=n)
	n=n->parent;
return n->parent;
